package nongchang.kuaijiecaifu.com.ncapp_android.ui.adapter.basketadapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import nongchang.kuaijiecaifu.com.ncapp_android.R;
import nongchang.kuaijiecaifu.com.ncapp_android.common.adapter.ItemAdapter;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.good.BasketMenu;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.good.BasketType;
import nongchang.kuaijiecaifu.com.ncapp_android.util.ScaleUtil;

/**
 * Created by Administrator on 2016/4/26 0026.
 */
public class BasketTypeAdapter extends ItemAdapter<BasketType, BasketTypeAdapter.BasketTypeViewHolder> {
    private Context context;

    public BasketTypeAdapter(Context context) {
        super(context);
        this.context = context;
    }
    private View.OnClickListener onBackGround;
    public void setOnBackGround(View.OnClickListener onBackGround) {
        this.onBackGround = onBackGround;
    }
    @Override
    public BasketTypeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BasketTypeViewHolder(inflate(R.layout.item_basket_type, parent));
    }

    @Override
    public void onBindViewHolder(BasketTypeViewHolder holder, int position) {
        BasketType item = getItem(position);
        holder.txtName.setText(item.name);
//        holder.imgIcon.setImageResource(item.image);
//        holder.txtName.setText(item.name);
        if (item.isselect) {
            holder.txtName.setTextColor(0xFF2ABAAB);
            holder.txtName.setBackgroundColor(Color.WHITE);
        } else {
            holder.txtName.setTextColor(0xDD000000);
            holder.txtName.setBackgroundColor(0xE5E8E8);
        }
        if(position==0){
            Drawable drawable=context.getResources().getDrawable(R.drawable.img_basket_rexiao);
            drawable.setBounds(0,0,drawable.getMinimumWidth(),drawable.getMinimumHeight());
            holder.txtName.setCompoundDrawables(drawable,null,null,null);
            holder.txtName.setPadding(ScaleUtil.dip2px(context,10),0,0,0);
            drawable=null;
        }
        holder.txtName.setOnClickListener(onBackGround);
        holder.txtName.setTag(position);
    }


    static class BasketTypeViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_name)
        TextView txtName;
//        @BindView(R.id.ll_layout)
//        LinearLayout linearLayout;
        public BasketTypeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

    }
}
